<?php

namespace App\Console\Commands;

use App\Jobs\Viewer;
use App\Services\CrawlerService\CrawlerService;
use App\Services\CrawlerService\driver\Xinxin21ccnnDriver;
use Illuminate\Console\Command;

class Discover extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'discover';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @param $driver
     * @return mixed
     */
    public function handle($driver = null)
    {

        if (!$driver) {
            $driver = Xinxin21ccnnDriver::class;
        }
//        $viewer=(new Viewer($driver,"http://www.21ccnn.com/plugin.php?id=aljzp&act=view&lid=44263"));
//        $viewer->handle();
//        dd('done');
        $server = new CrawlerService($driver);
        $list   = $server->setPage([1,5])->getList();
        foreach ($list as $item) {
            dispatch(new Viewer($driver, $item));
        }
    }
}
